package com.example.blogserver.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.blogserver.a_utils.ResponseBodyMessage;
import com.example.blogserver.pojo.User;
import com.example.blogserver.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @description
 * @descriptionDetail
 * @Author B3300
 * @copyright 摸鱼王胖嘟嘟
 * @Date 2024/3/19 21:57
 */

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @GetMapping("/getNowUser")
    public ResponseBodyMessage<User> getNowUser(HttpServletRequest request) {
        return adminService.getNowUser(request);
    }

    @GetMapping("/queryUserExceptOwn")
    public ResponseBodyMessage<List<User>> queryUserExceptOwn(HttpServletRequest request) {
        return adminService.queryUserAll(request);
    }

    @GetMapping("/page")
    public ResponseBodyMessage<Page> page(int page, int pageSize) {
        return adminService.page(page, pageSize);
    }

    @PostMapping("/updateIdentityByUserId")
    @Transactional
    public ResponseBodyMessage<Boolean> updateIdentityByUserId(HttpServletRequest request,
                                                               @RequestParam("identity") int identity,
                                                               @RequestParam("id") String id) {
        return adminService.updateIdentityByUserId(request, identity, id);
    }

}
